﻿using System.ComponentModel;

namespace CloudShot.Core.Utils
{
  public static class GenericConverter
  {
    public static T ConvertFromString<T>(string value)
    {
      TypeConverter tc = TypeDescriptor.GetConverter(typeof(T));
      return (T)tc.ConvertFromString(value);
    }

    public static string ConvertToString<T>(T value)
    {
      TypeConverter tc = TypeDescriptor.GetConverter(typeof(T));
      return tc.ConvertToString(value);
    }

    public static void RegisterTypeConverter<T, TC>() where TC : TypeConverter
    {
      TypeDescriptor.AddAttributes(typeof(T), new TypeConverterAttribute(typeof(TC)));
    }
  }
}